<template>
    <div>
        <a-modal v-model:visible="modalVisible" title="确认重启" @ok="handleOk" :confirm-loading="confirmLoading">
            <div class="fz-14 col-8A93A7">是否确认重启</div>
        </a-modal>
    </div>
</template>

<script setup>
import { defineProps, defineEmits, computed, ref } from 'vue';
import { handleInstance } from 'api/modules/api.instance'
import { XsyMessage } from '@/libs/util.toast'

const props = defineProps({
    modelValue: {
        type: Boolean,
    },
    instance: {
        type: Object,
        default: {}
    }
});

const emit = defineEmits(['update:modelValue', 'handelOpt']);
const modalVisible = computed({
    get: () => props.modelValue,
    set: v => emit('update:modelValue', v),
});


// 确定按钮的回调
const confirmLoading = ref(false)
const handleOk = () => {
    const params = {
        instanceId: props.instance?.Instance?.instanceId,
        method: 'restart'
    }
    confirmLoading.value = true
    handleInstance(params).then(res => {
        confirmLoading.value = false
        if (res.code == 0) {
            emit('update:modelValue', false)
            emit('handelOpt', props.instance?.Instance?.instanceId)
        }
    }).catch(()=> {
        confirmLoading.value = false
    })
};

</script>

